/* For general Scribus (>=1.3.2) copyright and licensing information please refer to the COPYING file provided with the program. Following this notice may exist a copyright and/or license notice that predates the release of Scribus 1.3.2 for which a new license (GPL+exception) is in place. */ #include "cmdtext.h" #include "cmdutil.h" #include "pageitem_textframe.h" #include "prefsmanager.h" #include "selection.h" #include "util.h" #include "scribuscore.h" #include "hyphenator.h" PyObject *scribus_getfontsize(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font size of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } if (it->HasSel) { for (int b = 0; b < it->itemText.length(); b++) if (it->itemText.selected(b)) return PyFloat_FromDouble(static_cast(it->itemText.charStyle(b).fontSize() / 10.0)); return NULL; } else return PyFloat_FromDouble(static_cast(it->currentCharStyle().fontSize() / 10.0)); } PyObject *scribus_getfont(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } if (it->HasSel) { for (int b = 0; b < it->itemText.length(); b++) if (it->itemText.selected(b)) return PyString_FromString(it->itemText.charStyle(b).font().scName().toUtf8()); return NULL; } else return PyString_FromString(it->currentCharStyle().font().scName().toUtf8()); } PyObject *scribus_gettextsize(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!(i->asTextFrame()) && !(i->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text size of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } return PyInt_FromLong(static_cast(i->itemText.length())); } PyObject *scribus_gettextlines(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!(i->asTextFrame()) && !(i->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get number of lines of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } return PyInt_FromLong(static_cast(i->itemText.lines())); } PyObject *scribus_getcolumns(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column count of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } return PyInt_FromLong(static_cast(i->Cols)); } PyObject *scribus_getlinespace(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get line space of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } return PyFloat_FromDouble(static_cast(i->currentStyle().lineSpacing())); } PyObject *scribus_gettextdistances(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text distances of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } return Py_BuildValue("(dddd)", PointToValue(i->textToFrameDistLeft()), PointToValue(i->textToFrameDistRight()), PointToValue(i->textToFrameDistTop()), PointToValue(i->textToFrameDistBottom())); } PyObject *scribus_getcolumngap(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get column gap of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } return PyFloat_FromDouble(PointToValue(static_cast(i->ColGap))); } PyObject *scribus_getframetext(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; QString text = ""; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } for (int a = it->firstInFrame(); a <= it->lastInFrame(); ++a) { if (it->HasSel) { if (it->itemText.selected(a)) text += it->itemText.text(a); } else { text += it->itemText.text(a); } } return PyString_FromString(text.toUtf8()); } PyObject *scribus_gettext(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; QString text = ""; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } // collect all chars from a storytext for (int a = 0; a < it->itemText.length(); a++) { if (it->HasSel) { if (it->itemText.selected(a)) text += it->itemText.text(a); } else { text += it->itemText.text(a); } } // for return PyString_FromString(text.toUtf8()); } PyObject *scribus_setboxtext(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); char *Text; if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Text, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name)); if (currItem == NULL) return NULL; if (!(currItem->asTextFrame()) && !(currItem->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } QString Daten = QString::fromUtf8(Text); Daten.replace("\r\n", SpecialChars::PARSEP); Daten.replace(QChar('\n') , SpecialChars::PARSEP); PyMem_Free(Text); currItem->itemText.clear(); for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a) { ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a; } currItem->itemText.insertChars(0, Daten); currItem->invalidateLayout(); currItem->Dirty = false; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_inserttext(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); char *Text; int pos; if (!PyArg_ParseTuple(args, "esi|es", "utf-8", &Text, &pos, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert text into non-text frame.","python error").toLocal8Bit().constData()); return NULL; } QString Daten = QString::fromUtf8(Text); Daten.replace("\r\n", SpecialChars::PARSEP); Daten.replace(QChar('\n') , SpecialChars::PARSEP); PyMem_Free(Text); if ((pos < -1) || (pos > static_cast(it->itemText.length()))) { PyErr_SetString(PyExc_IndexError, QObject::tr("Insert index out of bounds.","python error").toLocal8Bit().constData()); return NULL; } if (pos == -1) pos = it->itemText.length(); it->itemText.insertChars(pos, Daten); it->Dirty = true; if (ScCore->primaryMainWindow()->doc->DoDrawing) { // FIXME adapt to Qt-4 painting style // it->paintObj(); it->Dirty = false; } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_setalign(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); int alignment; if (!PyArg_ParseTuple(args, "i|es", &alignment, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if ((alignment > 4) || (alignment < 0)) { PyErr_SetString(PyExc_ValueError, QObject::tr("Alignment out of range. Use one of the scribus.ALIGN* constants.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text alignment on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->setNewAlignment(alignment); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_setfontsize(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); double size; if (!PyArg_ParseTuple(args, "d|es", &size, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if ((size > 512) || (size < 1)) { PyErr_SetString(PyExc_ValueError, QObject::tr("Font size out of bounds - must be 1 <= size <= 512.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->doc->itemSelection_SetFontSize(qRound(size * 10.0)); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_setfont(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); char *Font = const_cast(""); if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Font, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!(i->asTextFrame()) && !(i->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } if (PrefsManager::instance()->appPrefs.AvailFonts.contains(QString::fromUtf8(Font))) { int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->SetNewFont(QString::fromUtf8(Font)); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); } else { PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.","python error").toLocal8Bit().constData()); return NULL; } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_setlinespace(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); double w; if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (w < 0.1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Line space out of bounds, must be >= 0.1.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->doc->itemSelection_SetLineSpacing(w); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); // i->setLineSpacing(w); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_settextdistances(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); double l,r,t,b; if (!PyArg_ParseTuple(args, "dddd|es", &l, &r, &t, &b, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (l < 0.0 || r < 0.0 || t < 0.0 || b < 0.0) { PyErr_SetString(PyExc_ValueError, QObject::tr("Text distances out of bounds, must be positive.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text distances on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } i->setTextToFrameDist(ValueToPoint(l), ValueToPoint(r), ValueToPoint(t), ValueToPoint(b)); Py_INCREF(Py_None); return Py_None; } PyObject *scribus_setcolumngap(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); double w; if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (w < 0.0) { PyErr_SetString(PyExc_ValueError, QObject::tr("Column gap out of bounds, must be positive.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set column gap on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } i->ColGap = ValueToPoint(w); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_setcolumns(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); int w; if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (w < 1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Column count out of bounds, must be > 1.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set number of columns on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } i->Cols = w; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_selecttext(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); int start, selcount; if (!PyArg_ParseTuple(args, "ii|es", &start, &selcount, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (selcount == -1) { // user wants to select all after the start point -- CR selcount = it->itemText.length() - start; if (selcount < 0) // user passed start that's > text in the frame selcount = 0; } // cr 2005-01-18 fixed off-by-one with end bound that made selecting the last char impossible if ((start < 0) || ((start + selcount) > static_cast(it->itemText.length()))) { PyErr_SetString(PyExc_IndexError, QObject::tr("Selection index out of bounds", "python error").toLocal8Bit().constData()); return NULL; } if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot select text in a non-text frame", "python error").toLocal8Bit().constData()); return NULL; } /* FIXME: not sure if we should make this check or not if (start > ende) { PyErr_SetString(PyExc_ValueError, QString("Selection start > selection end").toLocal8Bit().constData()); return NULL; } */ it->itemText.deselectAll(); if (selcount == 0) { it->HasSel = false; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } it->itemText.select(start, selcount, true); it->HasSel = true; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_deletetext(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot delete text from a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } if (it->HasSel) dynamic_cast(it)->deleteSelectedTextFromFrame(); else { it->itemText.clear(); for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a) { ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a; } } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_settextfill(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); char *Color; if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text fill on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } else { for (int b = 0; b < it->itemText.length(); b++) { //FIXME: doc method if (it->HasSel) { if (it->itemText.selected(b)) it->itemText.item(b)->setFillColor(QString::fromUtf8(Color)); } else it->itemText.item(b)->setFillColor(QString::fromUtf8(Color)); } // it->TxtFill = QString::fromUtf8(Color); } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_settextstroke(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); char *Color; if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && (it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text stroke on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } else { for (int b = 0; b < it->itemText.length(); b++) { //FIXME:NLS use document method for this if (it->HasSel) { if (it->itemText.selected(b)) it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color)); } else it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color)); } // it->TxtStroke = QString::fromUtf8(Color); } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_settextscalingh(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); double sc; if (!PyArg_ParseTuple(args, "d|es", &sc, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (sc < 10) { PyErr_SetString(PyExc_ValueError, QObject::tr("Character scaling out of bounds, must be >= 10","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->doc->itemSelection_SetScaleH(qRound(sc * 10)); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); Py_RETURN_NONE; } PyObject *scribus_settextscalingv(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); double sc; if (!PyArg_ParseTuple(args, "d|es", &sc, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (sc < 10) { PyErr_SetString(PyExc_ValueError, QObject::tr("Character scaling out of bounds, must be >= 10","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->doc->itemSelection_SetScaleV(qRound(sc * 10)); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); Py_RETURN_NONE; } PyObject *scribus_settextshade(PyObject* /* self */, PyObject* args) { char *Name = const_cast(""); int w; if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if ((w < 0) || (w > 100)) { // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text shade on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } else { //FIXME:NLS use document method for that for (int b = 0; b < it->itemText.length(); ++b) { if (it->HasSel) { if (it->itemText.selected(b)) it->itemText.item(b)->setFillShade(w); } else it->itemText.item(b)->setFillShade(w); } // it->ShTxtFill = w; } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_linktextframes(PyObject* /* self */, PyObject* args) { char *name1; char *name2; if (!PyArg_ParseTuple(args, "eses", "utf-8", &name1, "utf-8", &name2)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *fromitem = GetUniqueItem(QString::fromUtf8(name1)); if (fromitem == NULL) return NULL; PageItem *toitem = GetUniqueItem(QString::fromUtf8(name2)); if (toitem == NULL) return NULL; if (!(fromitem->asTextFrame()) || !(toitem->asTextFrame())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only link text frames.","python error").toLocal8Bit().constData()); return NULL; } /* if (toitem->itemText.length() > 0) { PyErr_SetString(ScribusException, QObject::tr("Target frame must be empty.","python error").toLocal8Bit().constData()); return NULL; }*/ if (toitem->nextInChain() != 0) { PyErr_SetString(ScribusException, QObject::tr("Target frame links to another frame.","python error").toLocal8Bit().constData()); return NULL; } if (toitem->prevInChain() != 0) { PyErr_SetString(ScribusException, QObject::tr("Target frame is linked to by another frame.","python error").toLocal8Bit().constData()); return NULL; } if (toitem == fromitem) { PyErr_SetString(ScribusException, QObject::tr("Source and target are the same object.","python error").toLocal8Bit().constData()); return NULL; } // references to the others boxes fromitem->link(toitem); ScCore->primaryMainWindow()->view->DrawNew(); // enable 'save icon' stuff ScCore->primaryMainWindow()->slotDocCh(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_unlinktextframes(PyObject* /* self */, PyObject* args) { char *name; if (!PyArg_ParseTuple(args, "es", "utf-8", &name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *item = GetUniqueItem(QString::fromUtf8(name)); if (item == NULL) return NULL; if (!item->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot unlink a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } // only linked if (item->prevInChain() == 0) { PyErr_SetString(ScribusException, QObject::tr("Object is not a linked text frame, can't unlink.","python error").toLocal8Bit().constData()); return NULL; } /* if (item->NextBox == 0) { PyErr_SetString(ScribusException, QObject::tr("Object the last frame in a series, can't unlink. Unlink the previous frame instead.","python error").toLocal8Bit().constData()); return NULL; } */ /* PageItem* nextbox = item->NextBox; while (nextbox != 0) { uint a = nextbox->itemText.count(); for (uint s=0; sitemText.append(nextbox->itemText.take(0)); nextbox = nextbox->NextBox; } // while uint a2 = item->itemText.count(); for (uint s = 0; s < a2; ++s) item->BackBox->itemText.append(item->itemText.take(0)); */ item->prevInChain()->unlink(); // enable 'save icon' stuff ScCore->primaryMainWindow()->slotDocCh(); ScCore->primaryMainWindow()->view->DrawNew(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } /* * Convert the selected text frame to outlines. * * 2004-09-07 (Craig Ringer) * 2004-09-14 pv frame type, optional frame name param */ PyObject *scribus_tracetext(PyObject* /* self */, PyObject* args) { char *name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *item = GetUniqueItem(QString::fromUtf8(name)); if (item == NULL) return NULL; if (!item->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot convert a non-text frame to outlines.","python error").toLocal8Bit().constData()); return NULL; } if (item->invalid) item->layout(); ScCore->primaryMainWindow()->view->Deselect(true); ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr); ScCore->primaryMainWindow()->view->TextToPath(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_istextoverflowing(PyObject * self, PyObject* args, PyObject* kw) { int nolinks = 0; char *name = const_cast(""); char *kwargs[] = {const_cast("name"), const_cast("nolinks"), NULL}; if (!PyArg_ParseTupleAndKeywords(args, kw, "|esi", kwargs, "utf-8", &name, &nolinks)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *item = GetUniqueItem(QString::fromUtf8(name)); if (item == NULL) return NULL; if (!item->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Only text frames can be checked for overflowing", "python error").toLocal8Bit().constData()); return NULL; } /* original solution if (item->itemText.count() > item->MaxChars) return PyBool_FromLong(static_cast(true)); return PyBool_FromLong(static_cast(false)); */ /* uint firstFrame = 0; if (nolinks) firstFrame = item->itemText.count(); uint chars = item->itemText.count(); uint maxchars = item->MaxChars; while (item->NextBox != 0) { item = item->NextBox; chars += item->itemText.count(); maxchars += item->MaxChars; } // no overrun if (nolinks) return PyInt_FromLong(maxchars - firstFrame); if (maxchars > chars) return PyInt_FromLong(0); // number of overrunning letters return PyInt_FromLong(static_cast(chars - maxchars)); */ // refresh overflow information item->invalidateLayout(); item->layout(); return PyInt_FromLong(static_cast(item->frameOverflows())); } /* * Does hyphenation on the given text frame. * 08.12.2007: Joachim Neu */ PyObject *scribus_hyphenatetext(PyObject*, PyObject* args) { char *name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) return NULL; if (!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only hyphenate text frame", "python error").toLocal8Bit().constData()); return NULL; } ScCore->primaryMainWindow()->doc->docHyphenator->slotHyphenate(i); return PyBool_FromLong(1); } /* * Does dehyphenation on the given text frame. * 13.12.2007: Joachim Neu */ PyObject *scribus_dehyphenatetext(PyObject*, PyObject* args) { char *name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) return NULL; if (!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only dehyphenate text frame", "python error").toLocal8Bit().constData()); return NULL; } ScCore->primaryMainWindow()->doc->docHyphenator->slotDeHyphenate(i); return PyBool_FromLong(1); } PyObject *scribus_setpdfbookmark(PyObject* /* self */, PyObject* args) { char *name = const_cast(""); bool toggle; if (!PyArg_ParseTuple(args, "b|es", &toggle, "utf-8", &name)) return NULL; if (!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't set bookmark on a non-text frame", "python error").toLocal8Bit().constData()); return NULL; } if (i->isBookmark == toggle) { // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } if (toggle) { i->setIsAnnotation(false); ScCore->primaryMainWindow()->AddBookMark(i); } else ScCore->primaryMainWindow()->DelBookMark(i); i->isBookmark = toggle; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; } PyObject *scribus_ispdfbookmark(PyObject* /* self */, PyObject* args) { char *name = const_cast(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) return NULL; if (!checkHaveDocument()) return NULL; PageItem *i = GetUniqueItem(QString::fromUtf8(name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Can't get info from a non-text frame", "python error").toLocal8Bit().constData()); return NULL; } if (i->isBookmark) return PyBool_FromLong(1); return PyBool_FromLong(0); } /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV */ void cmdtextdocwarnings() { QStringList s; s << scribus_getfontsize__doc__ << scribus_getfont__doc__ << scribus_gettextlines__doc__ << scribus_gettextsize__doc__ << scribus_getframetext__doc__ << scribus_gettext__doc__ << scribus_getlinespace__doc__ << scribus_getcolumngap__doc__ << scribus_getcolumns__doc__ << scribus_setboxtext__doc__ << scribus_inserttext__doc__ << scribus_setfont__doc__ << scribus_setfontsize__doc__ << scribus_setlinespace__doc__ << scribus_setcolumngap__doc__ << scribus_setcolumns__doc__ << scribus_setalign__doc__ << scribus_selecttext__doc__ << scribus_deletetext__doc__ << scribus_settextfill__doc__ << scribus_settextstroke__doc__ << scribus_settextshade__doc__ << scribus_linktextframes__doc__ << scribus_unlinktextframes__doc__ << scribus_tracetext__doc__ << scribus_istextoverflowing__doc__ << scribus_setpdfbookmark__doc__ << scribus_ispdfbookmark__doc__ << scribus_hyphenatetext__doc__ << scribus_dehyphenatetext__doc__ << scribus_gettextdistances__doc__ << scribus_settextdistances__doc__ << scribus_settextscalingh__doc__ << scribus_settextscalingv__doc__; } '>843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
/*
   SSSD

   InfoPipe

   Copyright (C) Stephen Gallagher <sgallagh@redhat.com>	2009

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <dbus/dbus.h>
#include <ldb.h>
#include <time.h>
#include "util/util.h"
#include "util/btreemap.h"
#include "confdb/confdb.h"
#include "infopipe/infopipe.h"
#include "infopipe/infopipe_private.h"
#include "infopipe/sysbus.h"
#include "db/sysdb.h"

static int attr_comparator(const void *key1, const void *key2);
static int username_comparator(const void *key1, const void *key2);

struct infp_getcached_ctx {
    struct infp_req_ctx *infp_req;
    struct sysdb_req *sysdb_req;
    char **usernames;
    uint64_t min_last_login;
};
static void infp_users_get_cached_callback(void *ptr,
                                           int status,
                                           struct ldb_result *res)
{
    DBusMessage *reply;
    DBusMessageIter iter, array_iter;
    dbus_bool_t dbret;
    int i;
    char *username;
    struct infp_getcached_ctx *infp_getcached_req =
        talloc_get_type(ptr, struct infp_getcached_ctx);

    if (status != LDB_SUCCESS) {
        DEBUG(0, ("Failed to enumerate users in the cache db.\n"));
        talloc_free(infp_getcached_req);
        return;
    }

    /* Construct a reply */
    reply = dbus_message_new_method_return(infp_getcached_req->infp_req->req_message);
    if(reply == NULL) {
        talloc_free(infp_getcached_req);
        return;
    }

    dbus_message_iter_init_append(reply, &iter);
    dbret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                             "s", &array_iter);
    if (!dbret) goto error;

    for (i = 0; i < res->count; i++) {
        username = talloc_strdup(infp_getcached_req,
                                 ldb_msg_find_attr_as_string(res->msgs[i],
                                                             SYSDB_NAME,
                                                             NULL));
        if (username != NULL) {
            dbret = dbus_message_iter_append_basic(&array_iter,
                                                   DBUS_TYPE_STRING, &username);
            if (!dbret) goto error;
        }
    }
    dbret = dbus_message_iter_close_container(&iter, &array_iter);
    if(!dbret) goto error;

    sbus_conn_send_reply(infp_getcached_req->infp_req->sconn, reply);
    dbus_message_unref(reply);

    talloc_free(infp_getcached_req);
    return;

error:
    DEBUG(0,
          ("Critical error constructing reply message for %s\n",
            INFP_USERS_GET_CACHED));
    dbus_message_unref(reply);
    talloc_free(infp_getcached_req);
    return;
}

int infp_users_get_cached(DBusMessage *message, struct sbus_conn_ctx *sconn)
{
    DBusMessage *reply;
    DBusError error;
    dbus_bool_t dbret;
    char *einval_msg;
    char *search_expression;
    struct infp_getcached_ctx *infp_getcached_req;
    int ret;

    /* Arguments */
    const char *arg_domain;
    const uint64_t arg_minlastlogin;

    infp_getcached_req = talloc_zero(NULL, struct infp_getcached_ctx);
    if (infp_getcached_req == NULL) {
        ret = ENOMEM;
        goto error;
    }

    /* Create an infp_req_ctx */
    infp_getcached_req->infp_req =
        talloc_zero(infp_getcached_req, struct infp_req_ctx);
    if (infp_getcached_req == NULL) {
        ret = ENOMEM;
        goto error;
    }
    infp_getcached_req->infp_req->infp =
        talloc_get_type(sbus_conn_get_private_data(sconn), struct infp_ctx);
    infp_getcached_req->infp_req->sconn = sconn;
    infp_getcached_req->infp_req->req_message = message;
    infp_getcached_req->infp_req->caller =
        sysbus_get_caller(infp_getcached_req->infp_req,
                          infp_getcached_req->infp_req->req_message,
                          infp_getcached_req->infp_req->sconn);
    if (infp_getcached_req->infp_req->caller == NULL) {
        ret = EIO;
        goto error;
    }

    dbus_error_init(&error);
    dbret = dbus_message_get_args(message, &error,
                                  DBUS_TYPE_STRING, &arg_domain,
                                  DBUS_TYPE_UINT64, &arg_minlastlogin,
                                  DBUS_TYPE_INVALID);
    if(!dbret) {
        DEBUG(0, ("Parsing arguments to %s failed: %s:%s\n",
                INFP_USERS_GET_CACHED, error.name, error.message));
        einval_msg = talloc_strdup(infp_getcached_req, error.message);
        dbus_error_free(&error);
        goto einval;
    }

    infp_getcached_req->min_last_login = arg_minlastlogin;

    infp_getcached_req->infp_req->domain =
        btreemap_get_value(infp_getcached_req->infp_req->infp->domain_map,
                           (const void *)arg_domain);
    /* Check for a valid domain */
    if(infp_getcached_req->infp_req->domain == NULL) {
        einval_msg = talloc_strdup(infp_getcached_req, "Invalid domain.");
        goto einval;
    }

    /* NOTE: not checking permissions since the
     * information here is all visible in NSS as well
     */

    /* Call sysdb_enumpwent with special search parameters */
    search_expression = talloc_asprintf(infp_getcached_req,
                                        SYSDB_GETCACHED_FILTER,
                                        infp_getcached_req->min_last_login);
    ret = sysdb_enumpwent(infp_getcached_req,
                          infp_getcached_req->infp_req->infp->sysdb,
                          infp_getcached_req->infp_req->domain->name,
                          infp_getcached_req->infp_req->domain->legacy,
                          search_expression,
                          infp_users_get_cached_callback, infp_getcached_req);
    if(ret != EOK) {
        DEBUG(0, ("Could not read from the cache database.\n"));
        goto error;
    }

    return EOK;

einval:
    reply = dbus_message_new_error(message,
                                   DBUS_ERROR_INVALID_ARGS,
                                   einval_msg);
    if(reply == NULL) {
        ret = ENOMEM;
        goto error;
    }

    sbus_conn_send_reply(sconn, reply);
    dbus_message_unref(reply);
    talloc_free(infp_getcached_req);
    return EOK;

error:
    talloc_free(infp_getcached_req);
    return ret;
}

struct infp_createuser_ctx {
    struct infp_req_ctx *infp_req;
    struct sysdb_req *sysdb_req;

    char *username;
    char *fullname;
    char *homedir;
    char *shell;
};

static void infp_do_user_create_callback(void *pvt,
                                         int status,
                                         struct ldb_result *res)
{
    char *error_msg = NULL;
    DBusMessage *reply = NULL;
    struct infp_createuser_ctx *infp_createuser_req = talloc_get_type(pvt, struct infp_createuser_ctx);

    /* Commit the transaction if it we got a successful response, or cancel it if we did not */
    sysdb_transaction_done(infp_createuser_req->sysdb_req, status);

    /* Verify that the addition completed successfully
     * If LDB returned an error, run a search to determine
     * if it was due the requested username already being
     * in use
     */
    if (status == EOK) {
        /* Return reply ack */
        reply = dbus_message_new_method_return(infp_createuser_req->infp_req->req_message);
    }
    else if (status == EEXIST) {
        /* Return error, user already exists */
        error_msg = talloc_asprintf(infp_createuser_req,
                                    "User [%s] already exists on domain [%s]",
                                    infp_createuser_req->username,
                                    infp_createuser_req->infp_req->domain->name);
        reply = dbus_message_new_error(infp_createuser_req->infp_req->req_message,
                                       DBUS_ERROR_FILE_EXISTS,
                                       error_msg);
    }
    else {
        /* Unknown error occurred. Print DEBUG message */
        DEBUG(0, ("Failed to create user in the sysdb. Error code %d\n", status));
        talloc_free(infp_createuser_req);
        return;
    }

    if (reply) {
        sbus_conn_send_reply(infp_createuser_req->infp_req->sconn, reply);
        dbus_message_unref(reply);
    }
    talloc_free(infp_createuser_req);
}

static void infp_do_user_create(struct sysdb_req *req, void *pvt)
{
    int ret;
    struct infp_createuser_ctx *infp_createuser_req = talloc_get_type(pvt, struct infp_createuser_ctx);
    infp_createuser_req->sysdb_req = req;

    ret = sysdb_add_user(infp_createuser_req->sysdb_req,
                         infp_createuser_req->infp_req->domain,
                         infp_createuser_req->username,
                         0, 0,
                         infp_createuser_req->fullname,
                         infp_createuser_req->homedir,
                         infp_createuser_req->shell,
                         infp_do_user_create_callback,
                         infp_createuser_req);
    if (ret != EOK) {
        DEBUG(0, ("Could not invoke sysdb_add_user"));
        sysdb_transaction_done(infp_createuser_req->sysdb_req, ret);
        talloc_free(infp_createuser_req);
        return;
    }
}

int infp_users_create(DBusMessage *message, struct sbus_conn_ctx *sconn)
{
    DBusMessage *reply;
    DBusError error;
    dbus_bool_t dbret;
    char *einval_msg;
    struct infp_createuser_ctx *infp_createuser_req;
    int ret;

    /* Arguments */
    const char *arg_domain;
    const char *arg_username;
    const char *arg_fullname;
    const char *arg_homedir;
    const char *arg_shell;

    infp_createuser_req = talloc_zero(NULL, struct infp_createuser_ctx);
    if (infp_createuser_req == NULL) {
        ret = ENOMEM;
        goto error;
    }

    /* Create an infp_req_ctx */
    infp_createuser_req->infp_req = talloc_zero(infp_createuser_req, struct infp_req_ctx);
    if (infp_createuser_req == NULL) {
        ret = ENOMEM;
        goto error;
    }
    infp_createuser_req->infp_req->infp = talloc_get_type(sbus_conn_get_private_data(sconn), struct infp_ctx);
    infp_createuser_req->infp_req->sconn = sconn;
    infp_createuser_req->infp_req->req_message = message;
    infp_createuser_req->infp_req->caller = sysbus_get_caller(infp_createuser_req->infp_req,
                                                              infp_createuser_req->infp_req->req_message,
                                                              infp_createuser_req->infp_req->sconn);
    if (infp_createuser_req->infp_req->caller == NULL) {
        ret = EIO;
        goto error;
    }

    dbus_error_init(&error);
    dbret = dbus_message_get_args(message, &error,
                                  DBUS_TYPE_STRING, &arg_username,
                                  DBUS_TYPE_STRING, &arg_domain,
                                  DBUS_TYPE_STRING, &arg_fullname,
                                  DBUS_TYPE_STRING, &arg_homedir,
                                  DBUS_TYPE_STRING, &arg_shell,
                                  DBUS_TYPE_INVALID);
    if (!dbret) {
        DEBUG(0, ("Parsing arguments to %s failed: %s:%s\n", INFP_USERS_CREATE, error.name, error.message));
        einval_msg = talloc_strdup(infp_createuser_req, error.message);
        dbus_error_free(&error);
        goto einval;
    }

    /* FIXME: Allow creating users on domains other than LOCAL */
    if (strcasecmp(arg_domain, "LOCAL") != 0) {
        goto denied;
    }

    infp_createuser_req->infp_req->domain = btreemap_get_value(infp_createuser_req->infp_req->infp->domain_map,
                                                               (const void *)arg_domain);
    /* Check for a valid domain */
    if(infp_createuser_req->infp_req->domain == NULL) {
        einval_msg = talloc_strdup(infp_createuser_req, "Invalid domain.");
        goto einval;
    }

    if (strlen(arg_username)) {
        infp_createuser_req->username = talloc_strdup(infp_createuser_req, arg_username);
        if (infp_createuser_req->username == NULL) {
            ret = ENOMEM;
            goto error;
        }
    } else {
        einval_msg = talloc_strdup(infp_createuser_req, "No username provided");
        goto einval;
    }

    infp_createuser_req->fullname = NULL;
    if (strlen(arg_fullname)) {
        infp_createuser_req->fullname = talloc_strdup(infp_createuser_req, arg_username);
        if(infp_createuser_req->fullname == NULL) {
            ret = ENOMEM;
            goto error;
        }
    }

    infp_createuser_req->homedir = NULL;
    if (strlen(arg_homedir)) {
        infp_createuser_req->homedir = talloc_strdup(infp_createuser_req, arg_username);
        if(infp_createuser_req->homedir == NULL) {
            ret = ENOMEM;
            goto error;
        }
    }

    /* Check permissions */
    if(!infp_get_permissions(infp_createuser_req->infp_req->caller,
                             infp_createuser_req->infp_req->domain,
                             INFP_OBJ_TYPE_USER,
                             NULL,
                             INFP_ACTION_TYPE_CREATE,
                             INFP_ACTION_TYPE_INVALID)) goto denied;

    ret = sysdb_transaction(infp_createuser_req,
                            infp_createuser_req->infp_req->infp->sysdb,
                            infp_do_user_create,
                            infp_createuser_req);
    if (ret != EOK) {
        DEBUG(0,("Unable to start transaction to create user\n"));
        goto error;
    }

    return EOK;

denied:
    reply = dbus_message_new_error(message, DBUS_ERROR_ACCESS_DENIED, NULL);
    if(reply == NULL) {
        ret = ENOMEM;
        goto error;
    }
    /* send reply */
    sbus_conn_send_reply(sconn, reply);
    dbus_message_unref(reply);

    talloc_free(infp_createuser_req);
    return EOK;

einval:
    reply = dbus_message_new_error(message,
                                   DBUS_ERROR_INVALID_ARGS,
                                   einval_msg);
    if (reply == NULL) {
        ret = ENOMEM;
        goto error;
    }
    sbus_conn_send_reply(sconn, reply);
    dbus_message_unref(reply);
    talloc_free(infp_createuser_req);
    return EOK;

error:
    talloc_free(infp_createuser_req);
    return ret;
}

int infp_users_delete(DBusMessage *message, struct sbus_conn_ctx *sconn)
{
    DBusMessage *reply;

    reply = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented");

    /* send reply */
    sbus_conn_send_reply(sconn, reply);

    dbus_message_unref(reply);
    return EOK;
}

struct infp_getattr_ctx {
    struct infp_req_ctx *infp_req;
    char **usernames;
    uint32_t username_count;
    const char **attributes;
    uint32_t attr_count;
    uint32_t index;
    bool check_provider;

    /* The results array must have username_count elements */
    struct btreemap **results;
};

static int infp_get_attr_lookup(struct infp_getattr_ctx *infp_getattr_req);

struct infp_attr_variant {
    int dbus_type;
    int subtype;
    int count;
    void *data;
};

/* We are restricting variants to three basic types:
 * Fixed (Numeric) types
 * Strings
 * Arrays of fixed (numeric) types
 */
static int infp_user_getattr_append_dict(TALLOC_CTX *mem_ctx,
                                         DBusMessageIter *iter,
                                         struct btreemap *map)
{
    int ret, i;
    char **attrs;
    struct infp_attr_variant *value;
    char *vartype;
    char *subtype;
    int attr_count;
    DBusMessageIter array_iter;
    DBusMessageIter dict_iter;
    DBusMessageIter variant_iter;
    DBusMessageIter fixed_array_iter;
    dbus_bool_t dbret;

    ret = btreemap_get_keys(mem_ctx, map, (const void ***)&attrs, &attr_count);
    if (ret != EOK) {
        return ret;
    }

    /* DICTs are an array of dict pairs */
    dbret = dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "{sv}", &array_iter);
    if (!dbret) {
        ret = ENOMEM;
        goto error;
    }

    i = 0;
    while (i < attr_count) {
        if (strcasecmp(attrs[i], SYSDB_LAST_UPDATE) == 0) {
            /* Skip lastUpdate. We shouldn't be returning this */
            i++;
            continue;
        }

        /* Create the variant value */
        value = talloc_get_type(btreemap_get_value(map, attrs[i]), struct infp_attr_variant);
        if (value == NULL) {
            /* Skip any entries that returned an empty value */
            i++;
            continue;
        }

        /* Open a dict container for this pair */
        dbret = dbus_message_iter_open_container(&array_iter, DBUS_TYPE_DICT_ENTRY, NULL, &dict_iter);
        if (!dbret) {
            ret = ENOMEM;
            goto error;
        }
        /* Write the dict key */
        dbret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING, &attrs[i]);
        if (!dbret) {
            ret = ENOMEM;
            goto error;
        }

        vartype = NULL;
        subtype = NULL;
        if (sbus_is_dbus_string_type(value->dbus_type)) {
            /* String types are strings, object paths and signatures */
            vartype = talloc_asprintf(mem_ctx, "%c", value->dbus_type);
            if (vartype == NULL) {
                ret = ENOMEM;
                goto error;
            }
            dbret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT, vartype, &variant_iter);
            if (!dbret) {
                ret = ENOMEM;
                goto error;
            }
            dbret = dbus_message_iter_append_basic(&variant_iter, DBUS_TYPE_STRING, &value->data);
            if (!dbret) {
                ret = ENOMEM;
                goto error;
            }
            talloc_free(vartype);
            vartype = NULL;
        }

        else if (sbus_is_dbus_fixed_type(value->dbus_type)) {
            /* Fixed types are booleans, bytes, the integral types and the floating-point types */
            vartype = talloc_asprintf(mem_ctx, "%c", value->dbus_type);
            if (vartype == NULL) {
                ret = ENOMEM;
                goto error;
            }
            dbret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT, vartype, &variant_iter);
            if (!dbret) {
                ret = ENOMEM;
                goto error;
            }
            dbret = dbus_message_iter_append_basic(&variant_iter, value->dbus_type, value->data);
            if (!dbret) {
                ret = ENOMEM;
                goto error;
            }
            talloc_free(vartype);
            vartype = NULL;
        }

        else if (value->dbus_type == DBUS_TYPE_ARRAY) {
            if(sbus_is_dbus_fixed_type(value->subtype)) {
                /* Only support adding arrays of fixed types or strings for now */

                subtype = talloc_asprintf(mem_ctx, "a%c", value->subtype);
                if (subtype == NULL) {
                    ret = ENOMEM;
                    goto error;
                }
                dbret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT, subtype, &variant_iter);
                if (!dbret) {
                    ret = ENOMEM;
                    goto error;
                }

                dbret = dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY, subtype, &fixed_array_iter);
                if (!dbret) {
                    ret = ENOMEM;
                    goto error;
                }

                dbret = dbus_message_iter_append_fixed_array(&fixed_array_iter, value->subtype, &value->data, value->count);
                if(!dbret) {
                    ret = ENOMEM;
                    goto error;
                }

                dbret = dbus_message_iter_close_container(&variant_iter, &fixed_array_iter);
                if(!dbret) {
                    ret = ENOMEM;
                    goto error;
                }
            }
            else {
                ret = EINVAL;
                goto error;
            }
        }

        else {
            /* Value type not yet supported */
            DEBUG(0, ("Attempted to create DICT value for something not a basic type or fixed array [%d]\n", value->dbus_type));
            ret = EINVAL;
            goto error;
        }

        /* Close the variant */
        dbret = dbus_message_iter_close_container(&dict_iter, &variant_iter);
        if(!dbret) {
            ret = ENOMEM;
            goto error;
        }

        /* Close the dict */
        dbret = dbus_message_iter_close_container(&array_iter, &dict_iter);
        if(!dbret) {
            ret = ENOMEM;
            goto error;
        }
        i++;
    }

    /* Close the dict array */
    dbret = dbus_message_iter_close_container(iter, &array_iter);
    if(!dbret) {
        ret = ENOMEM;
        goto error;
    }

    return EOK;

error:
    talloc_free(attrs);
    talloc_free(vartype);
    talloc_free(subtype);
    return ret;
}

static int create_getattr_result_map(TALLOC_CTX *mem_ctx, struct infp_getattr_ctx *infp_getattr_req,
                                     struct ldb_result *res, struct btreemap **results)
{
    int i, ret;
    int attr_type;
    struct infp_attr_variant *variant;
    const struct ldb_val *val;

    /* Iterate through the requested attributes */
    for (i=0; i < infp_getattr_req->attr_count; i++) {
        /* Ignore any attributes we don't care about */
        attr_type = infp_get_attribute_type(infp_getattr_req->attributes[i]);
        if (attr_type != INFP_ATTR_TYPE_INVALID) {
            variant = talloc_zero(mem_ctx, struct infp_attr_variant);
            if (variant == NULL) {
                ret = ENOMEM;
                goto end;
            }

            variant->dbus_type = infp_get_user_attr_dbus_type(attr_type, &variant->subtype);
            if (sbus_is_dbus_string_type(variant->dbus_type)) {
                variant->data = (void *)talloc_strdup(variant, ldb_msg_find_attr_as_string(res->msgs[0],
                                                                                           infp_getattr_req->attributes[i], NULL));
                if (variant->data == NULL) {
                    talloc_free(variant);
                    continue;
                }
            }
            else if (sbus_is_dbus_fixed_type(variant->dbus_type)) {
                /* We'll treat all fixed(numeric) types as UINT64 internally
                 * These will be correctly converted to their true types
                 * when being marshalled on the wire.
                 */
                variant->data = (void *)talloc(variant, uint64_t);
                if (variant->data == NULL) {
                    talloc_free(variant);
                    continue;
                }

                *(uint64_t *)variant->data = ldb_msg_find_attr_as_uint64(res->msgs[0], infp_getattr_req->attributes[i], 0);
            }
            else if (variant->dbus_type == DBUS_TYPE_ARRAY) {
                switch(variant->subtype) {
                case DBUS_TYPE_BYTE:
                    /* Byte array (binary data) */
                    val = ldb_msg_find_ldb_val(res->msgs[0], infp_getattr_req->attributes[i]);
                    if (val == NULL || val->length <= 0) {
                        talloc_free(variant);
                        continue;
                    }
                    variant->data = talloc_memdup(variant, val->data, val->length);
                    if (variant->data == NULL) {
                        talloc_free(variant);
                        continue;
                    }
                    variant->count = val->length;
                    break;

                default:
                    /* Unsupported array type */
                    talloc_free(variant);
                    continue;
                }

            }
            else {
                /* Unsupported type */
                talloc_free(variant);
                continue;
            }

            /* Add the variant to the map */
            ret = btreemap_set_value(mem_ctx, results, (const void *)infp_getattr_req->attributes[i], variant, attr_comparator);
            if (ret != EOK) {
                talloc_free(variant);
            }
        }
    }

    ret = EOK;

end:
    return ret;
}

static void infp_get_attr_lookup_callback(void *ptr, int ldb_status, struct ldb_result *res)
{
    int ret;
    int i;
    bool call_provider = false;
    int timeout;
    uint64_t lastUpdate;
    DBusMessage *reply = NULL;
    DBusMessageIter iter;
    DBusMessageIter array_iter;
    struct infp_getattr_ctx *infp_getattr_req = talloc_get_type(ptr, struct infp_getattr_ctx);

    DEBUG(9, ("Processing results for user [%s]\n", infp_getattr_req->usernames[infp_getattr_req->index]));

    /* Process the current results */
    if (ldb_status != LDB_SUCCESS) {
        DEBUG(0, ("Critical error reading from sysdb.\n"));
        goto done;
    }

    if(infp_getattr_req->check_provider) {
        switch(res->count) {
        case 0:
            call_provider = true;
            break;

        case 1:
            timeout = infp_getattr_req->infp_req->infp->cache_timeout;
            lastUpdate = ldb_msg_find_attr_as_uint64(res->msgs[0],
                                                     SYSDB_LAST_UPDATE, 0);
            if (lastUpdate + timeout < time(NULL)) {
                call_provider = true;
            }
            break;

        default:
            DEBUG(0, ("GetUser call returned more than one result. This probably means the sysdb is corrupt!\n"));
            goto done;
        }
    }

    if (call_provider) {
        /* FIXME call the provider */
    }

    switch (res->count) {
    case 0:
        DEBUG(2, ("No results for GetUser"));
        infp_getattr_req->results[infp_getattr_req->index] = NULL;
        break;

    case 1:
        /* Create the result map */
        ret = create_getattr_result_map(infp_getattr_req, infp_getattr_req, res,
                                        &infp_getattr_req->results[infp_getattr_req->index]);
        if (ret != EOK) {
            DEBUG(0, ("Unable to create result map!\n"));
            goto done;
        }
        break;
    default:
        /* We received more than one result. This is bad */
        DEBUG(0, ("GetUser call returned more than one result. This probably means the sysdb is corrupt!\n"));
        goto done;
    }

    /* If there are more usernames remaining in the list, re-enter the loop */
    infp_getattr_req->index++;
    if (infp_getattr_req->index < infp_getattr_req->username_count) {
        ret = infp_get_attr_lookup(infp_getattr_req);
        if (ret != EOK) {
            DEBUG(0, ("Could not read from cache database\n"));
            goto done;
        }
        return;
    }

    /* No more names remain, return the result DICTs */
    reply = dbus_message_new_method_return(infp_getattr_req->infp_req->req_message);
    if (reply == NULL) {
        goto done;
    }

    dbus_message_iter_init_append(reply, &iter);

    dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "a{sv}", &array_iter);
    i = 0;
    while (i < infp_getattr_req->username_count) {
        ret = infp_user_getattr_append_dict(infp_getattr_req, &array_iter, infp_getattr_req->results[i]);
        if (ret != EOK) {
            DEBUG(0, ("Unable to append response DICT\n"));
            goto done;
        }
        i++;
    }
    dbus_message_iter_close_container(&iter, &array_iter);

    sbus_conn_send_reply(infp_getattr_req->infp_req->sconn, reply);

done:
    if(reply) dbus_message_unref(reply);
    talloc_free(infp_getattr_req);
}

int infp_get_user_attr_dbus_type(int attr_type, int *subtype)
{
    int dbus_type;
    *subtype = DBUS_TYPE_INVALID;

    switch(attr_type) {
    case INFP_ATTR_TYPE_DEFAULTGROUP:
    case INFP_ATTR_TYPE_GECOS:
    case INFP_ATTR_TYPE_HOMEDIR:
    case INFP_ATTR_TYPE_SHELL:
    case INFP_ATTR_TYPE_FULLNAME:
    case INFP_ATTR_TYPE_LOCALE:
    case INFP_ATTR_TYPE_KEYBOARD:
    case INFP_ATTR_TYPE_SESSION:
        dbus_type = DBUS_TYPE_STRING;
        break;
    case INFP_ATTR_TYPE_LAST_LOGIN:
        dbus_type = DBUS_TYPE_UINT64;
        break;
    case INFP_ATTR_TYPE_USERPIC:
        dbus_type = DBUS_TYPE_ARRAY;
        *subtype = DBUS_TYPE_BYTE;
        break;
    default:
        dbus_type = DBUS_TYPE_INVALID;
    }
    return dbus_type;
}

static int attr_comparator(const void *key1, const void *key2)
{
    return strcmp((const char *)key1, (const char *)key2);
}

static int infp_get_attr_lookup(struct infp_getattr_ctx *infp_getattr_req)
{
    uint32_t i;
    int ret;
    char **attributes;
    const char *last_update;
    int attr_count;

    DEBUG(9, ("Processing lookup for user [%s]\n", infp_getattr_req->usernames[infp_getattr_req->index]));

    if (infp_getattr_req->index >= infp_getattr_req->username_count) {
        /* Avoid index bound issues */
        return EINVAL;
    }

    /* Check permissions */
    i=0;
    infp_getattr_req->results[infp_getattr_req->index] = NULL;
    while(i < infp_getattr_req->attr_count) {
        if(infp_get_permissions(infp_getattr_req->infp_req->caller,
                                infp_getattr_req->infp_req->domain,
                                INFP_OBJ_TYPE_USER,
                                infp_getattr_req->usernames[infp_getattr_req->index],
                                INFP_ACTION_TYPE_READ,
                                infp_get_attribute_type(infp_getattr_req->attributes[i]))
        ) {
            /* Add this attribute as a key to the result map
             * This will guarantee that we are requesting only unique attributes
             * that we have permission to read
             */
            ret = btreemap_set_value(infp_getattr_req, &infp_getattr_req->results[infp_getattr_req->index],
                                     infp_getattr_req->attributes[i], NULL, attr_comparator);
            if (ret != EOK) {
                return ret;
            }
        }
        i++;
    }

    /* Always add SYSDB_LAST_UPDATE to the list, we won't return it */
    last_update = talloc_strdup(infp_getattr_req, SYSDB_LAST_UPDATE);
    ret = btreemap_set_value(infp_getattr_req, &infp_getattr_req->results[infp_getattr_req->index],
                             last_update, NULL, attr_comparator);
    if (ret != EOK) {
        return ret;
    }

    /* Prepare the list of attributes to request from the sysdb */
    attr_count = 0;
    ret = btreemap_get_keys(infp_getattr_req,
                            infp_getattr_req->results[infp_getattr_req->index],
                            (const void ***)&attributes, &attr_count);
    if (ret != EOK) {
        return ret;
    }

    if (attr_count == 1) {
        /* There were zero authorized attributes in the list
         * No need to call sysdb, just move to the next username
         * The single attribute was SYSDB_LAST_UPDATE which we
         * added manually.
         */
        infp_getattr_req->index++;
        return infp_get_attr_lookup(infp_getattr_req);
    }

    /* Add a trailing NULL entry (required for sysdb) */
    attributes = talloc_realloc(infp_getattr_req, attributes, char *, attr_count+1);
    if (attributes == NULL) {
        return ENOMEM;
    }
    attributes[attr_count] = NULL;

    /* Call into the sysdb for the requested attributes */
    ret = sysdb_get_user_attr(infp_getattr_req,
                              infp_getattr_req->infp_req->infp->sysdb,
                              infp_getattr_req->infp_req->domain->name,
                              infp_getattr_req->usernames[infp_getattr_req->index],
                              (const char **)attributes,
                              infp_getattr_req->infp_req->domain->legacy,
                              infp_get_attr_lookup_callback, infp_getattr_req);

    return EOK;
}

static const char **infp_get_all_attributes(TALLOC_CTX *mem_ctx,
                                            uint32_t *attr_count)
{
    const char **attributes;
    int offset = 0;

    *attr_count = 10;
    attributes = talloc_array(mem_ctx, const char *, *attr_count);
    if (attributes == NULL) {
        return NULL;
    }

    attributes[offset++] = SYSDB_USER_ATTR_DEFAULTGROUP;
    attributes[offset++] = SYSDB_USER_ATTR_GECOS;
    attributes[offset++] = SYSDB_USER_ATTR_HOMEDIR;
    attributes[offset++] = SYSDB_USER_ATTR_SHELL;
    attributes[offset++] = SYSDB_USER_ATTR_FULLNAME;
    attributes[offset++] = SYSDB_USER_ATTR_LOCALE;
    attributes[offset++] = SYSDB_USER_ATTR_KEYBOARD;
    attributes[offset++] = SYSDB_USER_ATTR_SESSION;
    attributes[offset++] = SYSDB_USER_ATTR_LAST_LOGIN;
    attributes[offset++] = SYSDB_USER_ATTR_USERPIC;

    return attributes;
}

/* GetUserAttributes(ARRAY(STRING) usernames,
 *                   STRING domain,
 *                   ARRAY(STRING) filter)
 */
int infp_users_get_attr(DBusMessage *message, struct sbus_conn_ctx *sconn)
{